package com.aabte.java8.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Java8特性之扩展注解
 * 注解可以添加在局部变量、泛型类、异常、父类和接口的实现
 */
public class ExtendAnnotations {

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    public @interface NonEmpty {
    }

    /**
     * 在泛型类和父类上使用注解
     * @param <T>
     */
    public static class Holder<@NonEmpty T> extends @NonEmpty Object {

        /**
         * @throws @NonEmpty Exception 在异常上使用注解
         */
        public void method() throws @NonEmpty Exception {}

    }

    public static void main(String[] args) {
        final Holder<String> stringHolder = new @NonEmpty Holder<>();
        @NonEmpty Collection<@NonEmpty String> stringList = new ArrayList<>();
    }

}
